package com.allwees.core.wf;

import lombok.Data;

import java.io.Serializable;

/**
 * 一条状态变迁定义（即：定义满足当前参数值时，变迁到哪个状态）
 *
 * @author yangylsky
 */
@Data
public class Transition<S extends FsmState<S, A>, A extends Action> implements Serializable {
	/**
	 * 触发变迁的动作
	 */
	private A action;

	/**
	 * 变迁的目标状态节点（back=true时无效）
	 */
	private S state;

	/**
	 * 当前变迁是否是回退（back=true时回退到当前状态的backState()）
	 */
	private boolean back;

	/**
	 * 构建无条件的变迁
	 *
	 * @param state
	 */
	public Transition(S state) {
		this(null, state);
	}

	/**
	 * 构建条件变迁
	 *
	 * @param action
	 * @param state
	 */
	public Transition(A action, S state) {
		this(action, state, false);
	}

	/**
	 * 构建条件回退变迁
	 *
	 * @param action
	 * @param back
	 */
	public Transition(A action, boolean back) {
		this(action, null, true);
	}

	/**
	 * 构建条件变迁
	 *
	 * @param action
	 * @param state
	 * @param back
	 */
	public Transition(A action, S state, boolean back) {
		this.action = action;
		if(!back && state != null) {
			this.state = state;
		}
		this.back = back;
	}
}
